#include <REGX52.H>
#include "AT24C02.h"
#include "IIC.h"
#include "LCD1602.h"
#include "Delay.h"
#include "Timer.h"
#include "MatrixKey.h"

unsigned int Second=0;
unsigned char KeyNumber;

void main(){
	unsigned int Temp;
	Timer0_Init();
	LCD1602_Init();
	LCD1602_PrintString(1,1,"SEC:");
	LCD1602_PrintString(2,1,"KEY:");
	while(1){
		KeyNumber=Key();
		Second++;
		// LCD1602_PrintNum(1,5,Second/100,2);
		// LCD1602_PrintNum(1, 7, Second % 100, 2);
		LCD1602_PrintNum(1, 5, Second, 4);
		Delay(100);
		if(KeyNumber==1)
		{
			AT24C02_WriteByte(0,Second%100);
			AT24C02_WriteByte(1,Second/100);
			LCD1602_PrintString(2,5,"WRIT OK");
		}
		else if(KeyNumber==2)
		{
			Temp=(AT24C02_ReadByte(1)*100+AT24C02_ReadByte(0));
			LCD1602_PrintString(2,5,"READ OK");
			// LCD1602_PrintNum(2,13,Temp/100,2);
			// LCD1602_PrintNum(2,15,Temp%100,2);
			LCD1602_PrintNum(2, 13, Temp, 4);
		}
		if(Second>=9999) {Second=0;}
	}
}